package servlet;

import java.io.IOException;
import java.sql.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.UserDAO;
import dao.UserDaoJdbcImpl;
import dao.UserInfoDAO;
import dao.UserInfoDaoJdbcImpl;
import modle.userInfo;
import modle.users;
import util.DateChange;

/**
 * Servlet implementation class UseAddServlet
 */
@WebServlet("/UseAddServlet")
public class UseAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UseAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		UserInfoDAO uInfo = new UserInfoDaoJdbcImpl();
		UserDAO u = new UserDaoJdbcImpl();
		
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		String usercredit = request.getParameter("usercredit");
		String name = request.getParameter("name");
		String userID = request.getParameter("userID");
		String usertel = request.getParameter("usertel");
		String userEmail = request.getParameter("userEmail");
		String userSex = request.getParameter("userSex");
		String userStatus = request.getParameter("userStatus");
		Date a = new Date(0, 0, 0);
		String dateStr = DateChange.sql_dateToString(a);
		int Status = Integer.parseInt(userStatus);
		System.out.println(userSex);
		users user = new users(userName,password);
		userInfo userInfo = new userInfo(usercredit,userName,name,userID,userSex,dateStr,userEmail,usertel,Status);
		
		u.writeUser(user);
		uInfo.writeUserInfo(userInfo);
		
		System.out.print(userSex);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
